<template>
  <div>
    <div class="home-bg"></div>

    <div class="home-footer">
      <img :src="button" @click="isFollow">
      <span class="home-just" @click="report">举报</span>
    </div>
  </div>
</template>
<script>
import utils from '../../utils'
export default {
  data () {
    return {
      id: this.$route.params.id,
      openid: '',
      subscribeStr: '',
      button: require('./image/metoo.png')
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      if (process.env.NODE_ENV !== 'development') {
        const openid = window.localStorage.getItem('openid')

        if (openid) {
          this.openid = openid
          return
        }
        let local = window.location.href
        let appid = 'wx7e2328fe819d9692'
        let code = utils.urlParam('code')
        if (code === null || code === '') {
          window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid + '&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_base&state=1#wechat_redirect'
        } else {
          this.getOpenId(code)
        }
      } else {
        this.openid = 'oJjc50xb8v2Ifd4pd2f4EkeYgkuM'
      }
    },
    getOpenId (code) {
      this.$http.post('/biaobeihy/wxUser/getOpenid', {
        code: code
      }).then(response => {
        console.log(response)
        if (response.data.openId) {
          this.openid = response.data.openId
          window.localStorage.setItem('openid', this.openid)
        } else {
          this.init()
        }
      })
    },
    report () {
      this.$http.post('/biaobeihy/userContent/update', {
        id: this.id,
        status: 2
      }).then(() => {
        alert('举报成功！')
      })
    },
    isFollow () {
      this.$http.post('/biaobeihy/wxUser/isFollow', {
        openid: this.openid
      }).then(response => {
        console.log(response)

        if (response.data.subscribeStr == '1') {
          this.$router.push('/edit-audio')
        } else {
          this.$router.push('/scan')
        }
      })
    }
  }
}
</script>
<style lang="less" scoped rel="stylesheet/less">
  .home-bg {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-image: url('./image/bg.png');
    background-size: 100% 100%;
  }

  .home-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 44px;
    text-align: center;

    > img {
      width: 200px;
      height: 50px;
      border-radius: 25px;
    }
  }

  .home-just {
    position: absolute;
    right: 30px;
    color: #f7e184;
    top: 17px;
    text-decoration: underline;
  }
</style>
